package com.qiantu.phone.widget.setting;

import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hjq.widget.layout.SettingBar;
import com.qiantu.api.entity.DeviceBean;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.ui.activity.DeviceSaveActivity;

/**
 * @description: 门铃推送
 */
public class DeviceSettingdoorPush extends SettingBar implements View.OnClickListener{
    private DeviceBean mDeviceBean;
    private AppActivity mContext;
    private String deviceSerialNo;

    public DeviceSettingdoorPush(AppActivity context, DeviceBean deviceBean, String title) {
        this(context,null,deviceBean,title);
    }

    public DeviceSettingdoorPush(AppActivity context, AttributeSet attrs, DeviceBean deviceBean, String title) {
        this(context, attrs,0,deviceBean,title);
    }

    public DeviceSettingdoorPush(AppActivity context, AttributeSet attrs, int defStyleAttr, DeviceBean deviceBean, String title) {
        this(context, attrs, defStyleAttr, R.style.setting_item_style,deviceBean,title);
    }

    public DeviceSettingdoorPush(@NonNull AppActivity context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes, DeviceBean deviceBean, String title) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mDeviceBean = deviceBean;
        mContext = context;
        setLeftText(title);
        setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        deviceSerialNo = deviceBean.getDeviceSerialNo();
        setOnClickListener(this::onClick);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(mContext, DeviceSaveActivity.class);
        intent.putExtra("deviceSerialNo",mDeviceBean.getDeviceSerialNo());
        mContext.startActivity(intent);
    }
}
